package net.csdn.business.common.oauth2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.common.oauth2.model.entity.OauthAccessToken;
import net.csdn.business.common.domain.request.oauth.OauthAccessTokenQuery;
import net.csdn.business.common.domain.vo.oauth.OauthAccessTokenVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * accessToken信息Mapper接口
 * 
 * @author zhangyl
 * @date 2022-11-08
 */
@Repository
public interface OauthAccessTokenMapper extends BaseMapper<OauthAccessToken>
{

    /**
     * 分页查询accessToken信息列表
     *
     * @param query 字典类型信息
     * @return 字典类型集合信息
     */
    @Select("<script> select id, object_id, token_id, token, authentication_id, user_name, client_id, authentication, refresh_token, expir_time,token_type, created_by, created_date, last_modified_by, last_modified_date" +
            "from oauth_access_token where token_type=1" +
            "<if test='query.tokenId != null  and query.tokenId != \"\"' >" +
            "AND token_id = #{query.tokenId}" +
            "</if>" +
            "<if test='query.clientId != null  and query.clientId != \"\"' >" +
            "AND client_id = #{query.clientId}" +
            "</if>" +
            "<if test='query.createdBy != null  and query.createdBy != \"\"' >" +
            "AND created_by = #{query.createdBy}" +
            "</if>" +
            "</script>")
    public List<OauthAccessTokenVO> findPageList(Page page, @Param("query") OauthAccessTokenQuery query);


    /**
     * 查询accessToken信息列表
     * 
     * @param query accessToken信息
     * @return accessToken信息集合
     */
    @Select("<script> select id, object_id, token_id, token, authentication_id, user_name, client_id, authentication, refresh_token,expir_time,token_type, created_by, created_date, last_modified_by, last_modified_date" +
            " from oauth_access_token where token_type=1 " +
            "<if test='query.clientId != null  and query.clientId != \"\"' >" +
            "AND client_id = #{query.clientId}" +
            "</if>" +
            "<if test='query.userName != null  and query.userName != \"\"' >" +
            "AND user_name = #{query.userName} " +
            "</if>" +
            "</script>")
    public List<OauthAccessTokenVO> selectOauthAccessTokenList(@Param("query") OauthAccessTokenQuery query);



    @Select("<script> select count(*) " +
            "from oauth_access_token " +
            "where token_type=1 and client_id= #{clientId} " +
            "</script>")
    public Integer findAuthUserNum(@Param("clientId") String clientId);


}
